<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""DTD/xhtml1-strict.dtd">
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%@taglib uri="/WEB-INF/fmt.tld" prefix="fmt"%>
<%@taglib uri="/WEB-INF/fn.tld" prefix="fn"%>
<%@taglib uri="/WEB-INF/el.tld" prefix="el"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<c:import url="/includes/css_inc.jsp"/>
		<c:import url="/includes/js_inc.jsp"/>
		<script>
			$(function(){
				$("#btnSearch").button({
		            icons: {
		                primary: "ui-icon-search"
		            }
		        }).click(function(){
					if(validateEmpty()){
		        		$("#searchForm").submit();
					}
		        });
				$("#budgetYearFilter").change(function(){
					document.getElementById("allocateCodeFilter").innerHTML = "";
					var dhtml = new DHTML();
					if($("#budgetYearFilter").val() != ""){
						$.ajax({
							type: "post",
							url: "/provacc/acc67",
							dataType: "json",
							async: false,
						    cache: false,
							data: {
								app: "ajax",
								job: "getAllocateLvl1",
								budgetYear: $("#budgetYearFilter").val()
							},
							success: function(data) {
								if(data.length > 0){
									dhtml.createElement(document.getElementById("allocateCodeFilter"), ["option","value="], "----- เลือก -----");
									for(var i=0;i<data.length;i++){
										dhtml.createElement(document.getElementById("allocateCodeFilter"), ["option","value="+data[i].code], data[i].code +" - "+ data[i].name);
									}
								}else{
									dhtml.createElement(document.getElementById("allocateCodeFilter"), ["option","value="], "----- เลือก -----");
									return false;
								}
							}
						});
					}
				});
				$("#allocateCodeFilter").change(function(){
					document.getElementById("allocateCodeLvl2Filter").innerHTML = "";
					var dhtml = new DHTML();
					if($("#allocateCodeFilter").val() != ""){
						$.ajax({
							type: "post",
							url: "/provacc/acc67",
							dataType: "json",
							async: false,
						    cache: false,
							data: {
								app: "ajax",
								job: "getAllocateLvl2",
								budgetYear: $("#budgetYearFilter").val(),
								allocateCode: $("#allocateCodeFilter").val()
							},
							success: function(data) {
								if(data.length > 0){
									dhtml.createElement(document.getElementById("allocateCodeLvl2Filter"), ["option","value="], "----- เลือก -----");
									for(var i=0;i<data.length;i++){
										dhtml.createElement(document.getElementById("allocateCodeLvl2Filter"), ["option","value="+data[i].code], data[i].code +" - "+ data[i].name);
									}
								}else{
									dhtml.createElement(document.getElementById("allocateCodeLvl2Filter"), ["option","value="], "----- เลือก -----");
									return false;
								}
							}
						});
					}
				});
			});
		</script>
	</head>
	<body>
		<c:import url="/apps/msg.jsp"/>
		<form class="acc67-form" name="searchForm" id="searchForm" action="${pageContext.request.contextPath}/acc6" method="post" target = "_blank">
		<input type="hidden" name="app" id="app" value="ACC6REPORT"/>
		<input type="hidden" name="job" id="job" value="ACC6REPORT003"/>
		<table width="100%" class="ui-widget ui-widget-content" border="0">
			<tr>
				<th align="left" class="acc67-header ui-widget-header" colspan="2"><b>${screenCode.ACC6REPORT003}</b></th>
			</tr>
			<tr>
				<td class="bold">จังหวัด : </td>
				<td>
					<c:if test="${userInfo.areaLevel =='3'}">
						<c:forEach var="data" items="${userInfo.listUserProvice}">
							${data.provinceName}
							<input type="hidden" name="provinceIdFilter" id="provinceIdFilter" value="${data.provinceId}">
						</c:forEach>
					</c:if>
					<c:if test="${userInfo.areaLevel=='1' || userInfo.areaLevel=='2'}">
						<select name="provinceIdFilter" id="provinceIdFilter">
							<option value="">เลือกทั้งหมด</option>
							<c:forEach var="data" items="${userInfo.listUserProvice}">
								<c:if test="${data.provinceId == provinceId}" var="provinceSeleted"/>
								<option value="${data.provinceId}" ${provinceSeleted?'selected':''}>${data.provinceName}</option>
							</c:forEach>
						</select>
						<!-- <span id="$provinceId" class="red">*</span> -->
					</c:if>
				</td>
			</tr>
			<tr>
				<td width="20%" class="bold">ปีงบประมาณ: </td>
				<td>
					<select name="budgetYearFilter" id="budgetYearFilter">
						<option value="">----- เลือก -----</option>
						<c:forEach items="${lsBudgetYear}" var="data">
							<c:if test="${budgetYear == data.BUDGET_YEAR}" var="selected"/>
							<option value="${data.BUDGET_YEAR}" ${selected?'selected':''}>${data.BUDGET_YEAR}</option>
						</c:forEach>
					</select>
					<span id="$budgetYear" class="red">*</span>
				</td>
			</tr>
			<tr>
				<td class="bold">กองทุน : </td>
				<td>
					<select name="allocateCodeFilter" id="allocateCodeFilter">
						<option value="">----- เลือก -----</option>
						<c:if test="${!empty lsAllocateLvl1}">
							<c:forEach items="${lsAllocateLvl1}" var="dataLvl1">
								<c:if test="${allocateCode == dataLvl1.ALLOCATE_CODE}" var="selected"/>
								<option value="${dataLvl1.ALLOCATE_CODE}" ${selected?'selected':''}>${dataLvl1.ALLOCATE_CODE} - ${dataLvl1.ALLOCATE_NAME}</option>
							</c:forEach>
						</c:if>
					</select>
					<span id="$allocateCode" class="red">*</span>
				</td>
			</tr>
			<tr>
				<td></td>
				<td>
					<select name="allocateCodeLvl2Filter" id="allocateCodeLvl2Filter">
						<option value="">----- เลือก -----</option>
						<c:if test="${!empty lsAllocateLvl2}">
							<c:forEach items="${lsAllocateLvl2}" var="dataLvl2">
								<c:if test="${allocateCodeLvl2 == dataLvl2.ALLOCATE_CODE}" var="selected"/>
								<option value="${dataLvl2.ALLOCATE_CODE}" ${selected?'selected':''}>${dataLvl2.ALLOCATE_CODE} - ${dataLvl2.ALLOCATE_NAME}</option>
							</c:forEach>
						</c:if>
					</select>
				</td>
			</tr>
			<tr>
				<td align="center" colspan="2">
					<button type="button" name="btnSearch" id="btnSearch" class="acc67-button"> ค้นหาข้อมูล </button>
				</td>
			</tr>
		</table>
		</form>
	</body>
</html>